package framework.core.util.sec;

import java.util.Properties;

import org.springframework.beans.factory.FactoryBean;

public class PropertiesEncryptFactoryBean implements FactoryBean<Object> {

	private Properties properties;
	
	public Object getObject() throws Exception {
		return getProperties();
	}

	public Class<Properties> getObjectType() {
		return java.util.Properties.class;
	}

	public boolean isSingleton() {
		return true;
	}

	public Properties getProperties() {
		return properties;
	}

	public void setProperties(Properties inProperties) {
		this.properties = inProperties;
		String originalUsername = properties.getProperty("user");
		String originalPassword = properties.getProperty("password");
		if (originalUsername != null){
			properties.put("user", AESUtil.decrypt(originalUsername));
		}
		if (originalPassword != null){
			properties.put("password", AESUtil.decrypt(originalPassword));
		}
	}
}

